package com.huike.clues.service.impl;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


import com.huike.clues.domain.HkBusiness;
import com.huike.clues.dto.HkBusinessDto;
import com.huike.clues.mapper.HkBusinessMapper;
import com.huike.clues.service.IHkBusinessService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;


/**
 * 商机;Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-07
 */
@Service
public class HkBusinessServiceImpl implements IHkBusinessService {
    @Autowired
    private HkBusinessMapper hkBusinessMapper;

    /**
     * 查询商机;
     *
     * @param id 商机;主键
     * @return 商机;
     */
    @Override
    public HkBusiness selectHkBusinessById(Long id) {
        return hkBusinessMapper.selectHkBusinessById(id);
    }

    /**
     * 查询商机;列表
     *
     * @param hkBusiness 商机;
     * @return 商机;
     */
    @Override
    public List<HkBusiness> selectHkBusinessList(HkBusinessDto hkBusiness) {

        return hkBusinessMapper.selectHkBusinessList(hkBusiness);
    }

    /**
     * 新增商机;
     *
     * @param hkBusiness 商机;
     * @return 结果
     */
    @Override
    public int insertHkBusiness(@RequestBody HkBusiness hkBusiness) {
        hkBusiness.setOwner("李晓明");
        hkBusiness.setStatus(1L);//吧状态改为商
        hkBusiness.setCreatedTime(LocalDateTime.now());
        hkBusiness.setBusinesStatu(0L);//待跟进


        return hkBusinessMapper.insertHkBusiness(hkBusiness);
    }

    /**
     * 修改商机;
     *
     * @param hkBusiness 商机;
     * @return 结果
     */
    @Override
    public int updateHkBusiness(HkBusiness hkBusiness) {

        hkBusiness.setBusinesStatu(1L);//跟进中
        hkBusiness.setUpdatedTime(LocalDateTime.now());
        return hkBusinessMapper.updateHkBusiness(hkBusiness);
    }

    /**
     * 批量删除商机;
     *
     * @param ids 需要删除的商机;主键
     * @return 结果
     */
    @Override
    public int deleteHkBusinessByIds(Long[] ids) {
        return hkBusinessMapper.deleteHkBusinessByIds(ids);
    }

    /**
     * 删除商机;信息
     *
     * @param id 商机;主键
     * @return 结果
     */
    @Override
    public int deleteHkBusinessById(Long id) {
        return hkBusinessMapper.deleteHkBusinessById(id);
    }

    /*
     * 公海池的查询
     * */
    @Override
    public List<HkBusiness> selectHkSeaPoolList(HkBusinessDto hkSeaPool) {

        return hkBusinessMapper.selectHkSeaPoolList(hkSeaPool);
    }

    //拉取公海
    @Override
    public void Fishing(Map ids) {
        List<Integer> list = (List) ids.get("ids");
        for (Integer l : list) {
            HkBusiness hkBusiness = hkBusinessMapper.selectHkBusinessById(Long.valueOf(l));
            hkBusiness.setStatus(1L);
            hkBusiness.setCreatedTime(LocalDateTime.now());
            hkBusiness.setRejectReason(null);//捞取回去把原因删除调
            hkBusinessMapper.updateHkBusiness(hkBusiness);
        }


    }
}
